package ua.eug.airv1.weapon;

import ua.eug.airv1.ImageProvider;
import ua.eug.airv1.map.Tile;
import ua.eug.airv1.utils.Config;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Pool.Poolable;

public class Explosion extends Actor implements Poolable{
	private int step;
	public Tile tile = Tile.ZTile;
	private float tSec = 0;

	@Override
    public void draw(Batch batch, float alpha){
		if (step>0)
			batch.draw(ImageProvider.Boom[step],getX(),getY());
    }
	
	@Override
    public void act(float sec){
		if (step>0) {
			tSec += sec;
			if(tSec < 0.2) return;
			tSec = 0;
			step ++;
			if (step >= Config.ExplosionSteps) {
				step = 0;
				// return to pool
				ExplosionPool.getInstance().removeExplosion(this);
			}
		}
	}

	@Override
	public void reset() {
		step = 0;
	}

	public void init() {
		step = 1;
	}

}
